package thread_pool;

import java.util.LinkedList;

public class TaskQueue {

	private final PoolWorker[] threads;
	private final LinkedList<Runnable> queue;

	public TaskQueue(int threadCount) {
		queue = new LinkedList<Runnable>();
		threads = new PoolWorker[threadCount];

		for (int i = 0; i < threadCount; i++) {
			threads[i] = new PoolWorker(queue);
			threads[i].start();
		}
	}

	
	public void execute(Runnable r) {
		synchronized ( queue ) {
			queue.addLast(r);
			queue.notify();
		}
	}

}
